package com.example.customeview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * @author Caleb_F
 * @description:
 * @date :2020-09-24 14:36
 */
public class MyGridAdapter extends RecyclerView.Adapter<MyGridAdapter.MyDemo1Holder> {
    private Context mContext;
    private List<String> mlist;

    public MyGridAdapter(Context mContext, List<String> mlist) {
        this.mContext = mContext;
        this.mlist = mlist;
    }

    @NonNull
    @Override
    public MyDemo1Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyDemo1Holder(LayoutInflater.from(mContext).inflate(R.layout.recycler_gird,parent
        ,false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyDemo1Holder holder, int position) {
        holder.myGirdText.setText(mlist.get(position));

    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }


    class MyDemo1Holder extends RecyclerView.ViewHolder {
      TextView myGirdText;

        public MyDemo1Holder(@NonNull View itemView) {
            super(itemView);
            myGirdText = (TextView) itemView.findViewById(R.id.my_gird_text);
        }
    }
}


